import { defineStore } from 'pinia'

export const useProjectStore = defineStore('project', {
  state: () => ({
    // 当前项目标题
    projectTitle: ''
  }),

  getters: {
    // 获取项目标题
    getProjectTitle: (state) => state.projectTitle,
    
    // 检查是否有项目标题
    hasProjectTitle: (state) => !!state.projectTitle
  },

  actions: {
    // 设置项目标题
    setProjectTitle(title) {
      if (title) {
        this.projectTitle = title
        console.log('项目标题已存储到全局状态:', title)
      }
    },

    // 清除项目标题
    clearProjectTitle() {
      this.projectTitle = ''
      console.log('项目标题已清除')
    },

    // 设置导航栏标题（如果有项目标题的话）
    setNavigationTitle() {
      if (this.projectTitle) {
        uni.setNavigationBarTitle({
          title: this.projectTitle
        })
        console.log('导航栏标题已设置为:', this.projectTitle)
        return true
      }
      return false
    }
  }
}) 